package com.study.aop.controller;

import com.alibaba.fastjson.JSON;
import com.study.aop.Util.ResponseUtil;
import com.study.aop.entity.UserEntity;
import com.study.aop.entity.common.ResponseEntity;
import com.study.aop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.misc.IOUtils;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author flwu
 * @date 2020/3/19 3:14 PM
 * @MOTTO 保持空杯和敬畏
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/user/list")
    public ResponseEntity list(HttpServletRequest request) {
        List<UserEntity> userList = userService.getUserList();
        //System.out.println("Content-type:" + request.getHeader("Content-type"));
        //System.out.println("name:" + request.getHeader("name"));
        return ResponseUtil.success(userList);
    }

    @RequestMapping(value = "/user/info")
    public String info() {
        return "wufaliang";
    }

    @RequestMapping(value = "/user/update", method = RequestMethod.POST)
    public ResponseEntity update(@RequestBody String data) {


        System.out.println("content:" + data);
        //System.out.println("content-type:" + request.getHeader("Content-type"));
        return ResponseUtil.success();
    }

    /*@RequestMapping(value = "/user/update", method = RequestMethod.POST)
    public ResponseEntity update(HttpServletRequest request) {

        try {
            BufferedReader reader = request.getReader();
            char[] buf = new char[512];
            int len = 0;
            StringBuffer contentBuffer = new StringBuffer();
            while ((len = reader.read(buf)) != -1) {
                contentBuffer.append(buf, 0, len);
            }
            System.out.println(contentBuffer.toString());

        } catch (IOException e) {
            e.printStackTrace();
        }

        System.out.println("content-type:" + request.getHeader("Content-type"));
        return ResponseUtil.success();
    }*/

}
